<!--
 * @Author: liangzhuo liangzhuo@chzu.com
 * @Date: 2022-05-07 10:49:22
 * @LastEditors: liangzhuo liangzhuo@chzu.com
 * @LastEditTime: 2022-05-07 11:10:53
 * @FilePath: \ruoyi-ui\src\components\dataDetails\chartTotalNum.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div :class="className" ref="chartDiv" :style="{ height: height, width: width }" />
</template>

<script>
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "@/views/dashboard/mixins/resize.js";

const animationDuration = 6000;

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      const size = this.$refs.chartDiv.offsetWidth;
      this.chart.setOption({
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
            label: {
              show: true,
            },
          },
        },
        grid: {
          left: "8%",
          top: "10%",
          right: "5%",
          bottom: "15%",
        },
        xAxis: {
          data: ["一", "二", "三", "四", "五", "六", "七", "八", "九"],
          axisLine: {
            show: true, //隐藏X轴轴线
            lineStyle: {
              color: "#163a5f",
              width: 1,
            },
          },
          axisTick: {
            show: false, //隐藏X轴刻度
            alignWithLabel: true,
          },
          axisLabel: {
            show: true,
            textStyle: {
              color: "#000", //X轴文字颜色
              fontSize: size / 25,
            },
            interval: 0,
          },
        },
        yAxis: [
          {
            type: "value",
            name: "",
            nameTextStyle: {
              color: "#000",
              fontSize: size / 25,
            },
            splitLine: {
              show: false,
              lineStyle: {
                width: 1,
                color: "#CED2DB",
              },
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: true, //隐藏X轴轴线
              lineStyle: {
                color: "#163a5f",
                width: 2,
              },
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: "#000",
                fontSize: size / 25,
              },
            },
          },
          {
            type: "value",
            name: "",
            nameTextStyle: {
              color: "#ffffff",
              fontSize: 16,
            },
            splitLine: {
              show: false,
              lineStyle: {
                width: 1,
                color: "#CED2DB",
              },
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false, //隐藏X轴轴线
              lineStyle: {
                color: "#163a5f",
                width: 2,
              },
            },
            axisLabel: {
              show: false,
              textStyle: {
                color: "#797A7F",
                fontSize: size / 25,
              },
            },
          },
        ],
        series: [
          {
            name: "下载数",
            type: "bar",
            barWidth: size / 25,
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "#c618e6",
                },
                {
                  offset: 0.5,
                  color: "#634bf3",
                },
                {
                  offset: 1,
                  color: "#007eff",
                },
              ]),
              barBorderRadius: [20, 20, 20, 20],
            },
            data: [2, 3, 4, 5, 6, 8, 9, 7, 8],
          },
          {
            // name: '背景',
            type: "bar",
            barWidth: size / 25,
            xAxisIndex: 0,
            yAxisIndex: 1,
            barGap: "-110%",
            data: [100, 100, 100, 100, 100, 100, 100, 100, 100], //背景阴影长度
            itemStyle: {
              normal: {
                color: "rgba(135,63,203,0.3)",
                barBorderRadius: [20, 20, 20, 20],
              },
            },
            tooltip: {
              show: false,
            },
            zlevel: 9,
          },
        ],
      });
    },
  },
};
</script>
